package util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class DBUtil2 {
	public static Connection createConnection() {
		Connection connection = null;
		try {
			InitialContext cxt = new InitialContext();
			DataSource ds = (DataSource)cxt.lookup("java:/comp/env/jdbc/myoracle");
			connection = ds.getConnection();
			System.out.println(connection);
		} catch (NamingException | SQLException e) {
			e.printStackTrace();
		}
		return connection;
	}
	
	public static void close(Connection connection,PreparedStatement pst,ResultSet rs){
		try {
			if(rs!=null)
				rs.close();
			if(pst!=null)
				pst.close();
			if(connection!=null)
				connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
